import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2022-10-13
 * Time: 18:31
 */
public class TestDemo1 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        for (int x : arr) {
            System.out.println(x);
        }
    }
    public static void main11(String[] args) {
        int[] arr = {1, 2, 3};
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
    public static void main10(String[] args) {
        int[] arr = {1, 2, 3};
        System.out.println(arr[100]);
    }
    public static void main9(String[] args) {
        int[] arr = {1, 2, 3};// 获取数组长度
        System.out.println("length: " + arr.length); // 执行结果: 3
        // 访问数组中的元素
        System.out.println(arr[1]); // 执行结果: 2
        System.out.println(arr[0]); // 执行结果: 1
        arr[2] = 100;
        System.out.println(arr[2]); // 执行结果: 100
    }
    //汉诺塔问题：
    public static void move(char pos1,char pos2) {
        System.out.print(pos1+"->"+pos2+" ");
    }//移动盘子的函数书写 从pos1移动到pos2

    /**
     *
     * @param n   代表你的盘子的个数
     * @param pos1  盘子所在的起始位置
     * @param pos2  盘子的中转位置
     * @param pos3  盘子的结束位置
     */
    public static void hanio(int n,char pos1,char pos2,char pos3) {
        if (n == 1) {
            move(pos1,pos3);
        } else {
            hanio(n-1,pos1,pos3,pos2);
            move(pos1,pos3);
            hanio(n-1,pos2,pos1,pos3);
        }
    }//汉诺塔总移动逻辑的书写
    public static void main8(String[] args) {
        hanio(1,'A','B','C');
        System.out.println();
        hanio(2,'A','B','C');
        System.out.println();
        hanio(3,'A','B','C');
        System.out.println();
    }
    //整形相加方法重载：
    public static int Sum(int a,int b){
        return a+b;
    }
    public static double Sum(double a,double b,double c){
        return a+b+c;
    }
    public static void main7(String[] args) {
        int a = 12;
        int b = 23;
        double c = 1.23;
        double d = 2.12;
        double e = 3.15;
        System.out.println(Sum(a,b));
        System.out.println(Sum(c,d,e));
    }
    //整形比较大小方法重载
    public static int Max(int a,int b){
        return a>b?a:b;
    }
    public static int Max(int a,int b,int c){
        return Max(Max(a,b),Max(b,c));
    }
    public static void main6(String[] args) {
        int a = 12;
        int b = 23;
        int c = 34;
        System.out.println(Max(a,b));
        System.out.println(Max(a,b,c));
    }
    //小青蛙跳台阶问题 for循环 迭代法：
    public static int frogJump2(int n){
        if (n == 1 || n == 2){
            return n;
        } else {
            int f1 = 1;
            int f2 = 2;
            int f3 = 0;
            for (int i = 3; i <= n; i++) {
                f3 = f1 + f2;
                f1 = f2;
                f2 = f3;
            }
            return f3;
        }
    }
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(frogJump(n));
    }
    //小青蛙跳台阶问题 递归法：
    public static int frogJump(int n){
        if (n == 1 || n == 2){
            return n;
        } else{
            return frogJump(n-1) + frogJump(n-2);
        }
    }
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(frogJump(n));
    }
    //求斐波那契数列的第n项 for循环 迭代法
    public static int fib2(int n){
        if (n == 1 || n == 2){
            return 1;
        } else {
            int f1 = 1;
            int f2 = 1;
            int f3 = 0;
            for (int i = 3; i <= n; i++) {
                f3 = f1 + f2;
                f1 = f2;
                f2 = f3;
            }
            return f3;
        }
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fib2(n));
    }
    //求斐波那契数列的第n项 递归法
    public static int fib(int n){
        if (n == 1 || n == 2){
            return 1;
        } else {
            return fib(n - 1) + fib(n - 2);
        }
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fib(n));
    }
    //打印一个数每一位的和：
    public static int sumEveryOne(int n){
        if (n < 1){
            return n;
        } else {
            return n % 10 + sumEveryOne(n/10);
        }
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(sumEveryOne(n));
    }
}
